subroutine simY_f(rand_u,w1,grid,n,smay,simTY1,indYT1,simTY2,indYT2)
INTEGER, INTENT(IN) :: n
REAL, INTENT(IN) :: rand_u, smay
REAL, INTENT(IN) :: w1(n,1), grid(n-1,1)
real, INTENT(OUT) :: simTY1, simTY2
INTEGER, INTENT(OUT) :: indYT1, indYT2
  
if (rand_u<w1(1,1)) then
   indYT1=1
   simTY1 = EXP(grid(1,1)*smay)
   indYT2=3 !reverse shock to generate mean zero across sims (apart from unemp.)
   simTY2 = EXP(grid(3,1)*smay)
else
   if (rand_u<w1(2,1)+w1(1,1)) then
      indYT1=2
      simTY1 = EXP(grid(2,1)*smay)
      indYT2=2
      simTY2 = EXP(grid(2,1)*smay)      
   else
      indYT1=3
      simTY1 = EXP(grid(3,1)*smay)
      indYT2=1  !reverse shock to generate mean zero across sims (apart from unemp.)
      simTY2 = EXP(grid(1,1)*smay)
  end if    
end if

end subroutine
